//
//  FMFileTool.m
//  FMDownLoad
//
//  Created by apple on 17/3/21.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "FMFileTool.h"

@implementation FMFileTool

+ (BOOL)createFilePathIfNotExist:(NSString *)filePath{
    
    NSFileManager *manager = [NSFileManager defaultManager];
    if (![manager fileExistsAtPath:filePath]) {
        NSError *error;
        [manager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:&error];
        if (error) {
            return NO;
        }
    }
    return YES;
}


+ (BOOL)fileExistsAtPath:(NSString *)filePath{
    
    return [[NSFileManager defaultManager] fileExistsAtPath:filePath];
}

+ (long long)fileSizeAtFilePah:(NSString *)filePath{
    if (![self fileExistsAtPath:filePath]) {
        return 0;
    }
    NSDictionary *infoDic = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
    return [infoDic[NSFileSize] longLongValue];
}

+ (void)removeFlieAtPath:(NSString *)filePath{
    if (![self fileExistsAtPath:filePath]) {
        return ;
    }
    [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
}

+ (void)moveFromPath:(NSString *)fromPath toPath:(NSString *)toPath{
    [[NSFileManager defaultManager] moveItemAtPath:fromPath toPath:toPath error:nil];
}


@end
